﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Caliburn.Micro;
using PocketBook.Tasks;

namespace PocketBook.ViewModels
{
    [Export(typeof(SelectPageViewModel)), PartCreationPolicy(CreationPolicy.NonShared)]
    public sealed class SelectPageViewModel : Screen, IDialog
    {
        private PageSiteViewModel _selectedPage;

        public event EventHandler<DialogResultCompletionEventArgs> Completed;

        public string Prompt
        {
            get; set;
        }

        public IEnumerable<PageSiteViewModel> PageList
        {
            get; set;
        }

        public PageSiteViewModel SelectedPage
        {
            get { return _selectedPage; }
            set
            {
                if (value == SelectedPage) return;

                _selectedPage = value;
                NotifyOfPropertyChange(() => CanSave);
            }
        }

        public bool CanSave
        {
            get { return SelectedPage != null; }
        }

        public void Save()
        {
            TryClose(true);
        }

        public void ActivateItem(PageSiteViewModel pageSite)
        {
            SelectedPage = pageSite;
            Save();
        }

    }
}